﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CapaPresentacion.Commands;
using CapaPresentacion.Vistas;
using Entidades;
using CapaLogica;
using System.Windows.Input;
using System.Windows;
using System.Windows.Data;
using System.Transactions;
using System.Windows.Controls;

namespace CapaPresentacion.Controles
{

    internal delegate void CargarActividadDidactica(int dia, Button boton, List<PlanificacionDiariaProyectoDidactico> ActividadesDelDia);


    class RealizarPlanificaciónProyectoDidácticoViewModel
    {

        public event ReiniciarCU ReiniciarCU;
        

        private RelayCommand saveCommand;
        private RelayCommand newCommand;
        private RelayCommand openCommand;
        private RelayCommand comenzarPlanificacionCommand;

        private PlanificacionProyectoDidactico planificacionProyectoDidactico;

        public List<ViewEntity> ListaMeses { get; set; }
        public List<ViewEntity> ListaProyectos { get; set; }


        public PlanificacionProyectoDidactico PlanificacionProyectoDidactico
        {
            get { return planificacionProyectoDidactico; }
            set { planificacionProyectoDidactico = value; }

        }      

        public ICommand SaveCommand
        {
            get
            {
                return saveCommand;
            }
        }

        public ICommand NewCommand
        {
            get
            {
                return newCommand;
            }
        }

        public ICommand OpenCommand
        {
            get
            {
                return openCommand;
            }
        }

        public ICommand ComenzarPlanificacionCommand
        {
            get
            {
                return comenzarPlanificacionCommand;
            }
        }

      
        

        RealizarPlanificaciónProyectoDidáctico view;

        public RealizarPlanificaciónProyectoDidácticoViewModel() { }

        public void Inicializar(RealizarPlanificaciónProyectoDidáctico vista)
        {
            ListaProyectos = new ProyectoDidacticoLogica().ObtenerProyectosDidacticos();

            if (ListaProyectos.Count > 0)
            {

                this.view = vista;
                this.planificacionProyectoDidactico = new PlanificacionProyectoDidactico();
                this.planificacionProyectoDidactico.IdPlanificacionProyectoDidactico = Guid.NewGuid();

                this.saveCommand = new RelayCommand(GuardarPlanificaciónProyectoDidáctico);
                this.newCommand = new RelayCommand(NuevaPlanificaciónProyectoDidáctico);
                this.openCommand = new RelayCommand(AbrirPlanificaciónProyectoDidáctico);
                this.comenzarPlanificacionCommand = new RelayCommand(ComenzarPlanificaciónProyectoDidáctico);

                this.planificacionProyectoDidactico.AñoPlanificacion = DateTime.Now.Year;

                ListaMeses = new List<ViewEntity>();
                ListaMeses.Add(new ViewEntity("Enero"));
                ListaMeses.Add(new ViewEntity("Febrero"));
                ListaMeses.Add(new ViewEntity("Marzo"));
                ListaMeses.Add(new ViewEntity("Abril"));
                ListaMeses.Add(new ViewEntity("Mayo"));
                ListaMeses.Add(new ViewEntity("Junio"));
                ListaMeses.Add(new ViewEntity("Julio"));
                ListaMeses.Add(new ViewEntity("Agosto"));
                ListaMeses.Add(new ViewEntity("Septiembre"));
                ListaMeses.Add(new ViewEntity("Octubre"));
                ListaMeses.Add(new ViewEntity("Noviembre"));
                ListaMeses.Add(new ViewEntity("Diciembre"));

                this.view.btn1.IsEnabled = false;
                this.view.btn7.IsEnabled = false;
                this.view.btn8.IsEnabled = false;
                this.view.btn14.IsEnabled = false;
                this.view.btn15.IsEnabled = false;
                this.view.btn21.IsEnabled = false;
                this.view.btn22.IsEnabled = false;
                this.view.btn28.IsEnabled = false;
                this.view.btn29.IsEnabled = false;
                this.view.btn35.IsEnabled = false;
                this.view.btn36.IsEnabled = false;


                this.view.gvTablero.Visibility = Visibility.Collapsed;
            }
            else
            {

                VentanaAviso nueva = new VentanaAviso(true, "Se ha producido un error", "No es posible realizar una planificación si no existen proyectos didácticos");
                nueva.ShowDialog();
                this.ReiniciarCU(CasosDeUso.NuevoProyectoDidactico);

            }

        }

        public void Inicializar(RealizarPlanificaciónProyectoDidáctico vista, PlanificacionProyectoDidactico entidad)
        {
            this.view = vista;
            this.planificacionProyectoDidactico = entidad;

            this.view.spDatosAlta.Visibility = Visibility.Collapsed;

            this.view.lblMes.Content = entidad.MesPlanificacion;
            this.view.lblAño.Content = entidad.AñoPlanificacion;
            this.view.lblProyecto.Content = entidad.ProyectoDidactico.NombreProyectoDidactico;
            this.view.spDatosModificacion.Visibility = Visibility.Visible;


            this.saveCommand = new RelayCommand(GuardarPlanificaciónProyectoDidáctico);
            this.newCommand = new RelayCommand(NuevaPlanificaciónProyectoDidáctico);
            this.openCommand = new RelayCommand(AbrirPlanificaciónProyectoDidáctico);

            this.view.btn1.IsEnabled = false;
            this.view.btn7.IsEnabled = false;
            this.view.btn8.IsEnabled = false;
            this.view.btn14.IsEnabled = false;
            this.view.btn15.IsEnabled = false;
            this.view.btn21.IsEnabled = false;
            this.view.btn22.IsEnabled = false;
            this.view.btn28.IsEnabled = false;
            this.view.btn29.IsEnabled = false;
            this.view.btn35.IsEnabled = false;
            this.view.btn36.IsEnabled = false;


            this.view.btn1.Content = "0";
            this.view.btn2.Content = "0";
            this.view.btn3.Content = "0";
            this.view.btn4.Content = "0";
            this.view.btn5.Content = "0";
            this.view.btn6.Content = "0";
            this.view.btn7.Content = "0";
            this.view.btn8.Content = "0";
            this.view.btn9.Content = "0";
            this.view.btn10.Content = "0";
            this.view.btn11.Content = "0";
            this.view.btn12.Content = "0";
            this.view.btn13.Content = "0";
            this.view.btn14.Content = "0";
            this.view.btn15.Content = "0";
            this.view.btn16.Content = "0";
            this.view.btn17.Content = "0";
            this.view.btn18.Content = "0";
            this.view.btn19.Content = "0";
            this.view.btn20.Content = "0";
            this.view.btn21.Content = "0";
            this.view.btn22.Content = "0";
            this.view.btn23.Content = "0";
            this.view.btn24.Content = "0";
            this.view.btn25.Content = "0";
            this.view.btn26.Content = "0";
            this.view.btn27.Content = "0";
            this.view.btn28.Content = "0";
            this.view.btn29.Content = "0";
            this.view.btn30.Content = "0";
            this.view.btn31.Content = "0";
            this.view.btn32.Content = "0";
            this.view.btn33.Content = "0";
            this.view.btn34.Content = "0";
            this.view.btn35.Content = "0";
            this.view.btn36.Content = "0";
            this.view.btn37.Content = "0";

            this.ComenzarPlanificaciónProyectoDidáctico(null);

            if(this.planificacionProyectoDidactico.PlanificacionesDiariasProyectoDidactico.Count > 0)
                this.CambiarEstiloDiaConActividades(this.planificacionProyectoDidactico.PlanificacionesDiariasProyectoDidactico);

        }

        private void NuevaPlanificaciónProyectoDidáctico(Object parameter)
        {
            if (MessageBox.Show("¿Está seguro que desea crear una nueva planificación didáctica?", "Confirme su Decisión", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
            {
                this.ReiniciarCU(CasosDeUso.NuevaPlanificacionProyectoDidactico);
            }
        }

        private void AbrirPlanificaciónProyectoDidáctico(Object parameter)
        {
            if (MessageBox.Show("¿Está seguro que desea editar los datos de una planificación didáctica existente?", "Confirme su Decisión", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
            {
                this.ReiniciarCU(CasosDeUso.BuscarPlanificacionProyectoDidactico);
            }
        }

        private void ComenzarPlanificaciónProyectoDidáctico(Object parameter)
        {

            if (Validaciones())
            {

                this.view.cmbMeses.IsEnabled = false;
                this.view.txtAñoPlanificacion.IsEnabled = false;
                this.view.cmbProyectos.IsEnabled = false;
                this.view.btnPlanificacion.IsEnabled = false;

                DateTime periodo = new DateTime(Convert.ToInt32(this.planificacionProyectoDidactico.AñoPlanificacion), this.ObtenerNumeroMes(this.planificacionProyectoDidactico.MesPlanificacion), 1);

                switch (periodo.DayOfWeek)
                {

                    case DayOfWeek.Sunday:
                       
                            this.view.btn1.Content = "1";
                            this.view.btn2.Content = "2";
                            this.view.btn3.Content = "3";
                            this.view.btn4.Content = "4";
                            this.view.btn5.Content = "5";
                            this.view.btn6.Content = "6";
                            this.view.btn7.Content = "7";
                            this.view.btn8.Content = "8";
                            this.view.btn9.Content = "9";
                            this.view.btn10.Content = "10";
                            this.view.btn11.Content = "11";
                            this.view.btn12.Content = "12";
                            this.view.btn13.Content = "13";
                            this.view.btn14.Content = "14";
                            this.view.btn15.Content = "15";
                            this.view.btn16.Content = "16";
                            this.view.btn17.Content = "17";
                            this.view.btn18.Content = "18";
                            this.view.btn19.Content = "19";
                            this.view.btn20.Content = "20";
                            this.view.btn21.Content = "21";
                            this.view.btn22.Content = "22";
                            this.view.btn23.Content = "23";
                            this.view.btn24.Content = "24";
                            this.view.btn25.Content = "25";
                            this.view.btn26.Content = "26";
                            this.view.btn27.Content = "27";
                            this.view.btn28.Content = "28";
                            this.view.btn29.Content = "29";
                            this.view.btn30.Content = "30";
                            this.view.btn31.Content = "31";


                            if (periodo.Month == 2)
                            {
                                if (DateTime.IsLeapYear(periodo.Year)) // Verificamos si es año bisiesto
                                {
                                    this.view.btn30.Visibility = Visibility.Hidden;
                                    this.view.btn31.Visibility = Visibility.Hidden;
                                    this.view.btn32.Visibility = Visibility.Hidden;
                                    this.view.btn33.Visibility = Visibility.Hidden;
                                    this.view.btn34.Visibility = Visibility.Hidden;
                                    this.view.btn35.Visibility = Visibility.Hidden;
                                    this.view.btn36.Visibility = Visibility.Hidden;
                                    this.view.btn37.Visibility = Visibility.Hidden; 
                                }
                                else
                                {
                                    this.view.btn29.Visibility = Visibility.Hidden;
                                    this.view.btn30.Visibility = Visibility.Hidden;
                                    this.view.btn31.Visibility = Visibility.Hidden;
                                    this.view.btn32.Visibility = Visibility.Hidden;
                                    this.view.btn33.Visibility = Visibility.Hidden;
                                    this.view.btn34.Visibility = Visibility.Hidden;
                                    this.view.btn35.Visibility = Visibility.Hidden;
                                    this.view.btn36.Visibility = Visibility.Hidden;
                                    this.view.btn37.Visibility = Visibility.Hidden; 
                                }


                            }
                        
                        else
                        {
                            if (periodo.Month == 1 || periodo.Month == 3 || periodo.Month == 5 || periodo.Month == 7 || periodo.Month == 8 || periodo.Month == 10 || periodo.Month == 12) // Meses que tienen 31 días
                            {
                                
                                this.view.btn32.Visibility = Visibility.Hidden;
                                this.view.btn33.Visibility = Visibility.Hidden;
                                this.view.btn34.Visibility = Visibility.Hidden;
                                this.view.btn35.Visibility = Visibility.Hidden;
                                this.view.btn36.Visibility = Visibility.Hidden;
                                this.view.btn37.Visibility = Visibility.Hidden; 

                            }
                            else
                            {
                                this.view.btn31.Visibility = Visibility.Hidden;
                                this.view.btn32.Visibility = Visibility.Hidden;
                                this.view.btn33.Visibility = Visibility.Hidden;
                                this.view.btn34.Visibility = Visibility.Hidden;
                                this.view.btn35.Visibility = Visibility.Hidden;
                                this.view.btn36.Visibility = Visibility.Hidden;
                                this.view.btn37.Visibility = Visibility.Hidden; 

                            }
                        }

                        break;

                    case DayOfWeek.Monday:

                            this.view.btn2.Content = "1";
                            this.view.btn3.Content = "2";
                            this.view.btn4.Content = "3";
                            this.view.btn5.Content = "4";
                            this.view.btn6.Content = "5";
                            this.view.btn7.Content = "6";
                            this.view.btn8.Content = "7";
                            this.view.btn9.Content = "8";
                            this.view.btn10.Content = "9";
                            this.view.btn11.Content = "10";
                            this.view.btn12.Content = "11";
                            this.view.btn13.Content = "12";
                            this.view.btn14.Content = "13";
                            this.view.btn15.Content = "14";
                            this.view.btn16.Content = "15";
                            this.view.btn17.Content = "16";
                            this.view.btn18.Content = "17";
                            this.view.btn19.Content = "18";
                            this.view.btn20.Content = "19";
                            this.view.btn21.Content = "20";
                            this.view.btn22.Content = "21";
                            this.view.btn23.Content = "22";
                            this.view.btn24.Content = "23";
                            this.view.btn25.Content = "24";
                            this.view.btn26.Content = "25";
                            this.view.btn27.Content = "26";
                            this.view.btn28.Content = "27";
                            this.view.btn29.Content = "28";
                            this.view.btn30.Content = "29";
                            this.view.btn31.Content = "30";
                            this.view.btn32.Content = "31";

                            if (periodo.Month == 2)
                            {
                                if (DateTime.IsLeapYear(periodo.Year)) // Verificamos si es año bisiesto
                                {

                                    this.view.btn1.Visibility = Visibility.Hidden;
                                    this.view.btn31.Visibility = Visibility.Hidden;
                                    this.view.btn32.Visibility = Visibility.Hidden;
                                    this.view.btn33.Visibility = Visibility.Hidden;
                                    this.view.btn34.Visibility = Visibility.Hidden;
                                    this.view.btn35.Visibility = Visibility.Hidden;
                                    this.view.btn36.Visibility = Visibility.Hidden;
                                    this.view.btn37.Visibility = Visibility.Hidden; 
                                }
                                else
                                {
                                    this.view.btn1.Visibility = Visibility.Hidden;
                                    this.view.btn30.Visibility = Visibility.Hidden;
                                    this.view.btn31.Visibility = Visibility.Hidden;
                                    this.view.btn32.Visibility = Visibility.Hidden;
                                    this.view.btn33.Visibility = Visibility.Hidden;
                                    this.view.btn34.Visibility = Visibility.Hidden;
                                    this.view.btn35.Visibility = Visibility.Hidden;
                                    this.view.btn36.Visibility = Visibility.Hidden;
                                    this.view.btn37.Visibility = Visibility.Hidden; 

                                }


                            }
                        
                        else
                        {
                            if (periodo.Month == 1 || periodo.Month == 3 || periodo.Month == 5 || periodo.Month == 7 || periodo.Month == 8 || periodo.Month == 10 || periodo.Month == 12) // Meses que tienen 31 días
                            {
                                
                                this.view.btn1.Visibility = Visibility.Hidden;
                                this.view.btn33.Visibility = Visibility.Hidden;
                                this.view.btn34.Visibility = Visibility.Hidden;
                                this.view.btn35.Visibility = Visibility.Hidden;
                                this.view.btn36.Visibility = Visibility.Hidden;
                                this.view.btn37.Visibility = Visibility.Hidden; 

                            }
                            else
                            {
                                this.view.btn1.Visibility = Visibility.Hidden;
                                this.view.btn32.Visibility = Visibility.Hidden;
                                this.view.btn33.Visibility = Visibility.Hidden;
                                this.view.btn34.Visibility = Visibility.Hidden;
                                this.view.btn35.Visibility = Visibility.Hidden;
                                this.view.btn36.Visibility = Visibility.Hidden;
                                this.view.btn37.Visibility = Visibility.Hidden; 

                            }
                        }

                        break;

                    case DayOfWeek.Tuesday:

                            this.view.btn3.Content = "1";
                            this.view.btn4.Content = "2";
                            this.view.btn5.Content = "3";
                            this.view.btn6.Content = "4";
                            this.view.btn7.Content = "5";
                            this.view.btn8.Content = "6";
                            this.view.btn9.Content = "7";
                            this.view.btn10.Content = "8";
                            this.view.btn11.Content = "9";
                            this.view.btn12.Content = "10";
                            this.view.btn13.Content = "11";
                            this.view.btn14.Content = "12";
                            this.view.btn15.Content = "13";
                            this.view.btn16.Content = "14";
                            this.view.btn17.Content = "15";
                            this.view.btn18.Content = "16";
                            this.view.btn19.Content = "17";
                            this.view.btn20.Content = "18";
                            this.view.btn21.Content = "19";
                            this.view.btn22.Content = "20";
                            this.view.btn23.Content = "21";
                            this.view.btn24.Content = "22";
                            this.view.btn25.Content = "23";
                            this.view.btn26.Content = "24";
                            this.view.btn27.Content = "25";
                            this.view.btn28.Content = "26";
                            this.view.btn29.Content = "27";
                            this.view.btn30.Content = "28";
                            this.view.btn31.Content = "29";
                            this.view.btn32.Content = "30";
                            this.view.btn33.Content = "31";

                            if (periodo.Month == 2)
                            {
                                if (DateTime.IsLeapYear(periodo.Year)) // Verificamos si es año bisiesto
                                {

                                    this.view.btn1.Visibility = Visibility.Hidden;
                                    this.view.btn2.Visibility = Visibility.Hidden;
                                    this.view.btn32.Visibility = Visibility.Hidden;
                                    this.view.btn33.Visibility = Visibility.Hidden;
                                    this.view.btn34.Visibility = Visibility.Hidden;
                                    this.view.btn35.Visibility = Visibility.Hidden;
                                    this.view.btn36.Visibility = Visibility.Hidden;
                                    this.view.btn37.Visibility = Visibility.Hidden; 
                                }
                                else
                                {
                                    this.view.btn1.Visibility = Visibility.Hidden;
                                    this.view.btn2.Visibility = Visibility.Hidden;
                                    this.view.btn31.Visibility = Visibility.Hidden;
                                    this.view.btn32.Visibility = Visibility.Hidden;
                                    this.view.btn33.Visibility = Visibility.Hidden;
                                    this.view.btn34.Visibility = Visibility.Hidden;
                                    this.view.btn35.Visibility = Visibility.Hidden;
                                    this.view.btn36.Visibility = Visibility.Hidden;
                                    this.view.btn37.Visibility = Visibility.Hidden; 

                                }

                            }
                        
                        else
                        {
                            if (periodo.Month == 1 || periodo.Month == 3 || periodo.Month == 5 || periodo.Month == 7 || periodo.Month == 8 || periodo.Month == 10 || periodo.Month == 12) // Meses que tienen 31 días
                            {
                                
                                this.view.btn1.Visibility = Visibility.Hidden;
                                this.view.btn2.Visibility = Visibility.Hidden;
                                this.view.btn34.Visibility = Visibility.Hidden;
                                this.view.btn35.Visibility = Visibility.Hidden;
                                this.view.btn36.Visibility = Visibility.Hidden;
                                this.view.btn37.Visibility = Visibility.Hidden; 


                            }
                            else
                            {
                                this.view.btn1.Visibility = Visibility.Hidden;
                                this.view.btn2.Visibility = Visibility.Hidden;
                                this.view.btn33.Visibility = Visibility.Hidden;
                                this.view.btn34.Visibility = Visibility.Hidden;
                                this.view.btn35.Visibility = Visibility.Hidden;
                                this.view.btn36.Visibility = Visibility.Hidden;
                                this.view.btn37.Visibility = Visibility.Hidden; 


                            }
                        }


                        break;

                    case DayOfWeek.Wednesday:

                            this.view.btn4.Content = "1";
                            this.view.btn5.Content = "2";
                            this.view.btn6.Content = "3";
                            this.view.btn7.Content = "4";
                            this.view.btn8.Content = "5";
                            this.view.btn9.Content = "6";
                            this.view.btn10.Content = "7";
                            this.view.btn11.Content = "8";
                            this.view.btn12.Content = "9";
                            this.view.btn13.Content = "10";
                            this.view.btn14.Content = "11";
                            this.view.btn15.Content = "12";
                            this.view.btn16.Content = "13";
                            this.view.btn17.Content = "14";
                            this.view.btn18.Content = "15";
                            this.view.btn19.Content = "16";
                            this.view.btn20.Content = "17";
                            this.view.btn21.Content = "18";
                            this.view.btn22.Content = "19";
                            this.view.btn23.Content = "20";
                            this.view.btn24.Content = "21";
                            this.view.btn25.Content = "22";
                            this.view.btn26.Content = "23";
                            this.view.btn27.Content = "24";
                            this.view.btn28.Content = "25";
                            this.view.btn29.Content = "26";
                            this.view.btn30.Content = "27";
                            this.view.btn31.Content = "28";
                            this.view.btn32.Content = "29";
                            this.view.btn33.Content = "30";
                            this.view.btn34.Content = "31";

                            if (periodo.Month == 2)
                            {
                                if (DateTime.IsLeapYear(periodo.Year)) // Verificamos si es año bisiesto
                                {

                                    this.view.btn1.Visibility = Visibility.Hidden;
                                    this.view.btn2.Visibility = Visibility.Hidden;
                                    this.view.btn3.Visibility = Visibility.Hidden;
                                    this.view.btn33.Visibility = Visibility.Hidden;
                                    this.view.btn34.Visibility = Visibility.Hidden;
                                    this.view.btn35.Visibility = Visibility.Hidden;
                                    this.view.btn36.Visibility = Visibility.Hidden;
                                    this.view.btn37.Visibility = Visibility.Hidden; 
                                }
                                else
                                {
                                    this.view.btn1.Visibility = Visibility.Hidden;
                                    this.view.btn2.Visibility = Visibility.Hidden;
                                    this.view.btn3.Visibility = Visibility.Hidden;
                                    this.view.btn32.Visibility = Visibility.Hidden;
                                    this.view.btn33.Visibility = Visibility.Hidden;
                                    this.view.btn34.Visibility = Visibility.Hidden;
                                    this.view.btn35.Visibility = Visibility.Hidden;
                                    this.view.btn36.Visibility = Visibility.Hidden;
                                    this.view.btn37.Visibility = Visibility.Hidden; 


                                }


                            }
                        
                        else
                        {
                            if (periodo.Month == 1 || periodo.Month == 3 || periodo.Month == 5 || periodo.Month == 7 || periodo.Month == 8 || periodo.Month == 10 || periodo.Month == 12) // Meses que tienen 31 días
                            {
                                
                                this.view.btn1.Visibility = Visibility.Hidden;
                                this.view.btn2.Visibility = Visibility.Hidden;
                                this.view.btn3.Visibility = Visibility.Hidden;
                                this.view.btn35.Visibility = Visibility.Hidden;
                                this.view.btn36.Visibility = Visibility.Hidden;
                                this.view.btn37.Visibility = Visibility.Hidden; 


                            }
                            else
                            {
                                this.view.btn1.Visibility = Visibility.Hidden;
                                this.view.btn2.Visibility = Visibility.Hidden;
                                this.view.btn3.Visibility = Visibility.Hidden;
                                this.view.btn34.Visibility = Visibility.Hidden;
                                this.view.btn35.Visibility = Visibility.Hidden;
                                this.view.btn36.Visibility = Visibility.Hidden;
                                this.view.btn37.Visibility = Visibility.Hidden; 


                            }
                        }

                        break;

                    case DayOfWeek.Thursday:

                            this.view.btn5.Content = "1";
                            this.view.btn6.Content = "2";
                            this.view.btn7.Content = "3";
                            this.view.btn8.Content = "4";
                            this.view.btn9.Content = "5";
                            this.view.btn10.Content = "6";
                            this.view.btn11.Content = "7";
                            this.view.btn12.Content = "8";
                            this.view.btn13.Content = "9";
                            this.view.btn14.Content = "10";
                            this.view.btn15.Content = "11";
                            this.view.btn16.Content = "12";
                            this.view.btn17.Content = "13";
                            this.view.btn18.Content = "14";
                            this.view.btn19.Content = "15";
                            this.view.btn20.Content = "16";
                            this.view.btn21.Content = "17";
                            this.view.btn22.Content = "18";
                            this.view.btn23.Content = "19";
                            this.view.btn24.Content = "20";
                            this.view.btn25.Content = "21";
                            this.view.btn26.Content = "22";
                            this.view.btn27.Content = "23";
                            this.view.btn28.Content = "24";
                            this.view.btn29.Content = "25";
                            this.view.btn30.Content = "26";
                            this.view.btn31.Content = "27";
                            this.view.btn32.Content = "28";
                            this.view.btn33.Content = "29";
                            this.view.btn34.Content = "30";
                            this.view.btn35.Content = "31";

                            if (periodo.Month == 2)
                            {
                                if (DateTime.IsLeapYear(periodo.Year)) // Verificamos si es año bisiesto
                                {

                                    this.view.btn1.Visibility = Visibility.Hidden;
                                    this.view.btn2.Visibility = Visibility.Hidden;
                                    this.view.btn3.Visibility = Visibility.Hidden;
                                    this.view.btn4.Visibility = Visibility.Hidden;
                                    this.view.btn34.Visibility = Visibility.Hidden;
                                    this.view.btn35.Visibility = Visibility.Hidden;
                                    this.view.btn36.Visibility = Visibility.Hidden;
                                    this.view.btn37.Visibility = Visibility.Hidden; 
                                }
                                else
                                {
                                    this.view.btn1.Visibility = Visibility.Hidden;
                                    this.view.btn2.Visibility = Visibility.Hidden;
                                    this.view.btn3.Visibility = Visibility.Hidden;
                                    this.view.btn4.Visibility = Visibility.Hidden;
                                    this.view.btn33.Visibility = Visibility.Hidden;
                                    this.view.btn34.Visibility = Visibility.Hidden;
                                    this.view.btn35.Visibility = Visibility.Hidden;
                                    this.view.btn36.Visibility = Visibility.Hidden;
                                    this.view.btn37.Visibility = Visibility.Hidden; 

                                }


                            }
                        
                        else
                        {
                            if (periodo.Month == 1 || periodo.Month == 3 || periodo.Month == 5 || periodo.Month == 7 || periodo.Month == 8 || periodo.Month == 10 || periodo.Month == 12) // Meses que tienen 31 días
                            {
                                
                                this.view.btn1.Visibility = Visibility.Hidden;
                                this.view.btn2.Visibility = Visibility.Hidden;
                                this.view.btn3.Visibility = Visibility.Hidden;
                                this.view.btn4.Visibility = Visibility.Hidden;
                                this.view.btn36.Visibility = Visibility.Hidden;
                                this.view.btn37.Visibility = Visibility.Hidden; 


                            }
                            else
                            {
                                this.view.btn1.Visibility = Visibility.Hidden;
                                this.view.btn2.Visibility = Visibility.Hidden;
                                this.view.btn3.Visibility = Visibility.Hidden;
                                this.view.btn4.Visibility = Visibility.Hidden;
                                this.view.btn35.Visibility = Visibility.Hidden;
                                this.view.btn36.Visibility = Visibility.Hidden;
                                this.view.btn37.Visibility = Visibility.Hidden; 

                            }
                        }

                        break;

                    case DayOfWeek.Friday:

                            this.view.btn6.Content = "1";
                            this.view.btn7.Content = "2";
                            this.view.btn8.Content = "3";
                            this.view.btn9.Content = "4";
                            this.view.btn10.Content = "5";
                            this.view.btn11.Content = "6";
                            this.view.btn12.Content = "7";
                            this.view.btn13.Content = "8";
                            this.view.btn14.Content = "9";
                            this.view.btn15.Content = "10";
                            this.view.btn16.Content = "11";
                            this.view.btn17.Content = "12";
                            this.view.btn18.Content = "13";
                            this.view.btn19.Content = "14";
                            this.view.btn20.Content = "15";
                            this.view.btn21.Content = "16";
                            this.view.btn22.Content = "17";
                            this.view.btn23.Content = "18";
                            this.view.btn24.Content = "19";
                            this.view.btn25.Content = "20";
                            this.view.btn26.Content = "21";
                            this.view.btn27.Content = "22";
                            this.view.btn28.Content = "23";
                            this.view.btn29.Content = "24";
                            this.view.btn30.Content = "25";
                            this.view.btn31.Content = "26";
                            this.view.btn32.Content = "27";
                            this.view.btn33.Content = "28";
                            this.view.btn34.Content = "29";
                            this.view.btn35.Content = "30";
                            this.view.btn36.Content = "31";

                            if (periodo.Month == 2)
                            {
                                if (DateTime.IsLeapYear(periodo.Year)) // Verificamos si es año bisiesto
                                {

                                    this.view.btn1.Visibility = Visibility.Hidden;
                                    this.view.btn2.Visibility = Visibility.Hidden;
                                    this.view.btn3.Visibility = Visibility.Hidden;
                                    this.view.btn4.Visibility = Visibility.Hidden;
                                    this.view.btn5.Visibility = Visibility.Hidden;
                                    this.view.btn35.Visibility = Visibility.Hidden;
                                    this.view.btn36.Visibility = Visibility.Hidden;
                                    this.view.btn37.Visibility = Visibility.Hidden; 
                                }
                                else
                                {
                                    this.view.btn1.Visibility = Visibility.Hidden;
                                    this.view.btn2.Visibility = Visibility.Hidden;
                                    this.view.btn3.Visibility = Visibility.Hidden;
                                    this.view.btn4.Visibility = Visibility.Hidden;
                                    this.view.btn5.Visibility = Visibility.Hidden;
                                    this.view.btn34.Visibility = Visibility.Hidden;
                                    this.view.btn35.Visibility = Visibility.Hidden;
                                    this.view.btn36.Visibility = Visibility.Hidden;
                                    this.view.btn37.Visibility = Visibility.Hidden; 

                                }


                            }
                        
                        else
                        {
                            if (periodo.Month == 1 || periodo.Month == 3 || periodo.Month == 5 || periodo.Month == 7 || periodo.Month == 8 || periodo.Month == 10 || periodo.Month == 12) // Meses que tienen 31 días
                            {
                                
                                this.view.btn1.Visibility = Visibility.Hidden;
                                this.view.btn2.Visibility = Visibility.Hidden;
                                this.view.btn3.Visibility = Visibility.Hidden;
                                this.view.btn4.Visibility = Visibility.Hidden;
                                this.view.btn5.Visibility = Visibility.Hidden;
                                this.view.btn37.Visibility = Visibility.Hidden; 

                            }
                            else
                            {
                                this.view.btn1.Visibility = Visibility.Hidden;
                                this.view.btn2.Visibility = Visibility.Hidden;
                                this.view.btn3.Visibility = Visibility.Hidden;
                                this.view.btn4.Visibility = Visibility.Hidden;
                                this.view.btn5.Visibility = Visibility.Hidden;
                                this.view.btn36.Visibility = Visibility.Hidden;
                                this.view.btn37.Visibility = Visibility.Hidden; 

                            }
                        }

                        break;

                    case DayOfWeek.Saturday:

                            this.view.btn7.Content = "1";
                            this.view.btn8.Content = "2";
                            this.view.btn9.Content = "3";
                            this.view.btn10.Content = "4";
                            this.view.btn11.Content = "5";
                            this.view.btn12.Content = "6";
                            this.view.btn13.Content = "7";
                            this.view.btn14.Content = "8";
                            this.view.btn15.Content = "9";
                            this.view.btn16.Content = "10";
                            this.view.btn17.Content = "11";
                            this.view.btn18.Content = "12";
                            this.view.btn19.Content = "13";
                            this.view.btn20.Content = "14";
                            this.view.btn21.Content = "15";
                            this.view.btn22.Content = "16";
                            this.view.btn23.Content = "17";
                            this.view.btn24.Content = "18";
                            this.view.btn25.Content = "19";
                            this.view.btn26.Content = "20";
                            this.view.btn27.Content = "21";
                            this.view.btn28.Content = "22";
                            this.view.btn29.Content = "23";
                            this.view.btn30.Content = "24";
                            this.view.btn31.Content = "25";
                            this.view.btn32.Content = "26";
                            this.view.btn33.Content = "27";
                            this.view.btn34.Content = "28";
                            this.view.btn35.Content = "29";
                            this.view.btn36.Content = "30";
                            this.view.btn37.Content = "31";

                            if (periodo.Month == 2)
                            {
                                if (DateTime.IsLeapYear(periodo.Year)) // Verificamos si es año bisiesto
                                {

                                    this.view.btn1.Visibility = Visibility.Hidden;
                                    this.view.btn2.Visibility = Visibility.Hidden;
                                    this.view.btn3.Visibility = Visibility.Hidden;
                                    this.view.btn4.Visibility = Visibility.Hidden;
                                    this.view.btn5.Visibility = Visibility.Hidden;
                                    this.view.btn6.Visibility = Visibility.Hidden;
                                    this.view.btn36.Visibility = Visibility.Hidden;
                                    this.view.btn37.Visibility = Visibility.Hidden; 
                                }
                                else
                                {
                                    this.view.btn1.Visibility = Visibility.Hidden;
                                    this.view.btn2.Visibility = Visibility.Hidden;
                                    this.view.btn3.Visibility = Visibility.Hidden;
                                    this.view.btn4.Visibility = Visibility.Hidden;
                                    this.view.btn5.Visibility = Visibility.Hidden;
                                    this.view.btn6.Visibility = Visibility.Hidden;
                                    this.view.btn35.Visibility = Visibility.Hidden;
                                    this.view.btn36.Visibility = Visibility.Hidden;
                                    this.view.btn37.Visibility = Visibility.Hidden; 

                                }


                            }
                        
                        else
                        {
                            if (periodo.Month == 1 || periodo.Month == 3 || periodo.Month == 5 || periodo.Month == 7 || periodo.Month == 8 || periodo.Month == 10 || periodo.Month == 12) // Meses que tienen 31 días
                            {
                                
                                this.view.btn1.Visibility = Visibility.Hidden;
                                this.view.btn2.Visibility = Visibility.Hidden;
                                this.view.btn3.Visibility = Visibility.Hidden;
                                this.view.btn4.Visibility = Visibility.Hidden;
                                this.view.btn5.Visibility = Visibility.Hidden;
                                this.view.btn6.Visibility = Visibility.Hidden; 

                            }
                            else
                            {
                                this.view.btn1.Visibility = Visibility.Hidden;
                                this.view.btn2.Visibility = Visibility.Hidden;
                                this.view.btn3.Visibility = Visibility.Hidden;
                                this.view.btn4.Visibility = Visibility.Hidden;
                                this.view.btn5.Visibility = Visibility.Hidden;
                                this.view.btn6.Visibility = Visibility.Hidden;
                                this.view.btn37.Visibility = Visibility.Hidden; 

                            }
                        }

                        break;


                }

                List<DiaFeriado> ListaDiasFeriados = new List<DiaFeriado>();
                ListaDiasFeriados = new DiaFeriadoLogica().ObtenerFeriadosPorAño(periodo);


                if (ListaDiasFeriados.Count > 0)
                {
                    this.CambiarEstiloDiaFeriado(ListaDiasFeriados);

                }


                this.view.gvTablero.Visibility = Visibility.Visible;


            }
        }


        private void GuardarPlanificaciónProyectoDidáctico(Object parameter)
        {
            if (MessageBox.Show("¿Está seguro que desea guardar los datos?", "Confirme su Decisión", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
            {
                if (Validaciones())
                {

                    try
                    {

                        if (!new PlanificacionProyectoDidacticoLogica().ExisteEntidad(this.planificacionProyectoDidactico.IdPlanificacionProyectoDidactico)) // Nueva planificación didáctica 
                        {
                            new PlanificacionProyectoDidacticoLogica().Agregar(this.planificacionProyectoDidactico);

                            VentanaAviso nueva = new VentanaAviso(false, "Finalización Exitosa", "La planificación didáctica ha sido creada correctamente");
                            nueva.ShowDialog();

                        }
                        else                        // Edición planificación didáctica 
                        {

                            new PlanificacionProyectoDidacticoLogica().Modificar(this.planificacionProyectoDidactico);

                            VentanaAviso nueva = new VentanaAviso(false, "Finalización Exitosa", "La planificación didáctica ha sido modificada correctamente");
                            nueva.ShowDialog();

                        }


                    }

                    catch (Exception)
                    {

                        VentanaAviso nueva = new VentanaAviso(true, "Se ha producido un error", "Ha ocurrido un error y la planificación didáctica no se ha guardado");
                        nueva.ShowDialog();

                    }


                }

            }

        }


        public void btn_Click(object sender, RoutedEventArgs e)
        {
            if (new ActividadDidacticaLogica().ExistenEntidades())
            {

                Button btn = (Button)sender;

                if (btn.Style != this.view.Resources["ButtonWeekend"] as Style)
                {

                    var Actividades = (from v in this.planificacionProyectoDidactico.PlanificacionesDiariasProyectoDidactico
                                       where v.Dia.ToString() == btn.Content.ToString() &&
                                        v.Eliminada != true
                                       select v).ToList();


                    VentanaCargaActividadesDidacticas ventana = new VentanaCargaActividadesDidacticas();
                    VentanaCargaActividadesDidacticasViewModel vcadVM = new VentanaCargaActividadesDidacticasViewModel(ventana, Actividades, btn, Convert.ToInt32(btn.Content), this.planificacionProyectoDidactico);

                    vcadVM.CargarActividadDidactica += OnCargarActividadesDiarias;
                    ventana.DataContext = vcadVM;

                    ventana.ShowDialog();

                }
            }
            else
            {
                VentanaAviso nueva = new VentanaAviso(true, "Se ha producido un error", "No se han encontrado Actividades Didácticas cargadas en el sistema");
                nueva.ShowDialog();


            }

        }



        internal void OnCargarActividadesDiarias(int diaPlanificacion,Button boton, List<PlanificacionDiariaProyectoDidactico> ActividadesDelDia)
        {

            var ExistenEntidadesDia = (from q in this.planificacionProyectoDidactico.PlanificacionesDiariasProyectoDidactico
                                    where   q.Dia == diaPlanificacion &&
                                            q.Eliminada != true
                                    select q).Any();

            if (ExistenEntidadesDia)
            {

                bool eliminados = false;

                while (eliminados == false)
                {
                    int i = 0;

                    foreach (var item in this.planificacionProyectoDidactico.PlanificacionesDiariasProyectoDidactico)
                    {
                        if (item.Dia != diaPlanificacion)
                            i++;
                        else
                            if (item.Eliminada != true)
                                break;
                            else
                                i++;
                    }
                    this.planificacionProyectoDidactico.PlanificacionesDiariasProyectoDidactico[i].Eliminada = true;

                    var ExistenEntidades = (from q in this.planificacionProyectoDidactico.PlanificacionesDiariasProyectoDidactico
                                            where q.Dia == diaPlanificacion &&
                                                    q.Eliminada != true
                                            select q).Any();

                    if (!ExistenEntidades)
                        eliminados = true;

                }

            }

            if (ActividadesDelDia.Count > 0)
            {

                foreach (var item in ActividadesDelDia)
                    this.planificacionProyectoDidactico.PlanificacionesDiariasProyectoDidactico.Add(item);
            }

            this.ActualizarEstadoControl(boton);

        }

        internal void ActualizarEstadoControl(Button boton)
        {

            var Actividades = (from v in this.planificacionProyectoDidactico.PlanificacionesDiariasProyectoDidactico
                               where v.Dia.ToString() == boton.Content.ToString() &&
                                                       v.Eliminada != true
                            select v).ToList();

            if (Actividades.Count > 0)
            {
                boton.Style = this.view.Resources["ButtonWithActivities"] as Style;

                boton.ToolTip = "Lista de Actividades planificadas para este día: \n \n";                

                foreach (var item in Actividades)
                {
                    ActividadDidactica entidad = new ActividadDidacticaLogica().ObtenerEntidad(item.IdActividadDidactica);

                    if (item.ActividadDidactica.DuracionActividad == 1)
                        boton.ToolTip = boton.ToolTip + entidad.NombreActividad + " (" + entidad.DuracionActividad + " minuto) \n"; 
                    else
                        boton.ToolTip = boton.ToolTip + entidad.NombreActividad + " (" + entidad.DuracionActividad + " minutos) \n"; 

                }



            }
            else
            {

                boton.Style = this.view.Resources["ButtonDay"] as Style;
                boton.ToolTip = "Haga click para agregar actividades didácticas";

            }

        }









        private bool Validaciones()
        {

            if (this.planificacionProyectoDidactico.AñoPlanificacion.ToString().Length != 4)
            {
                VentanaAviso nueva = new VentanaAviso(true, "Se ha producido un error", "El campo 'Año' ha sido ingresado de forma incorrecta");
                nueva.ShowDialog();
                return false;

            }

            if (String.IsNullOrWhiteSpace(this.planificacionProyectoDidactico.MesPlanificacion))
            {
                VentanaAviso nueva = new VentanaAviso(true, "Se ha producido un error", "Debe seleccionar un mes");
                nueva.ShowDialog();
                return false;
            }

            if (this.planificacionProyectoDidactico.IdProyectoDidactico == Guid.Empty)
            {
                VentanaAviso nueva = new VentanaAviso(true, "Se ha producido un error", "Debe seleccionar un proyecto didáctico");
                nueva.ShowDialog();
                return false;
            }

            if (new PlanificacionProyectoDidacticoLogica().ExistePlanificacion(this.planificacionProyectoDidactico.IdPlanificacionProyectoDidactico, this.planificacionProyectoDidactico.MesPlanificacion, this.planificacionProyectoDidactico.AñoPlanificacion))
            {
                VentanaAviso nueva = new VentanaAviso(true, "Se ha producido un error", "Ya existe una planificación para el mes y año seleccionados");
                nueva.ShowDialog();
                return false;
            }

            if (!new TurnoLogica().ExistenTurnosAñoSeleccionado(this.planificacionProyectoDidactico.AñoPlanificacion))
            {
                VentanaAviso nueva = new VentanaAviso(true, "Se ha producido un error", "No existen turnos creados para el año seleccionado");
                nueva.ShowDialog();
                return false;

            }

            CicloLectivo ciclo = new CicloLectivoLogica().ObtenerEntidad(this.planificacionProyectoDidactico.AñoPlanificacion);

            if (ciclo.FechaDesde.Value.Month > ObtenerNumeroMes(this.planificacionProyectoDidactico.MesPlanificacion))
            {
                VentanaAviso nueva = new VentanaAviso(true, "Se ha producido un error", "La planificación didáctica debe estar contenida dentro del período del ciclo lectivo");
                nueva.ShowDialog();
                return false;

            }

            if (ciclo.FechaHasta.Value.Month < ObtenerNumeroMes(this.planificacionProyectoDidactico.MesPlanificacion))
            {
                VentanaAviso nueva = new VentanaAviso(true, "Se ha producido un error", "La planificación didáctica debe estar contenida dentro del período del ciclo lectivo");
                nueva.ShowDialog();
                return false;

            }


            return true;


        }

        
        internal int ObtenerNumeroMes(string mes)
        {

            switch(mes)
            {

                case "Enero":
                    return 1;

                case "Febrero":
                    return 2;

                case "Marzo":
                    return 3;
                
                case "Abril":
                    return 4;

                case "Mayo":
                    return 5;

                case "Junio":
                    return 6;

                case "Julio":
                    return 7;

                case "Agosto":
                    return 8;

                case "Septiembre":
                    return 9;

                case "Octubre":
                    return 10;

                case "Noviembre":
                    return 11;

                case "Diciembre":
                    return 12;

                default: return 0;

            }


        }

        internal string ObtenerNombreMes(int mes)
        {

            switch (mes)
            {

                case 1:
                    return "Enero";

                case 2:
                    return "Febrero";

                case 3:
                    return "Marzo";

                case 4:
                    return "Abril";

                case 5:
                    return "Mayo";

                case 6:
                    return "Junio";

                case 7:
                    return "Julio";

                case 8:
                    return "Agosto";

                case 9:
                    return "Septiembre";

                case 10:
                    return "Octubre";

                case 11:
                    return "Noviembre";

                case 12:
                    return "Diciembre";

                default: return "Ninguno";

            }

        }


        internal void CambiarEstiloDiaFeriado(List<DiaFeriado> ListaDiasFeriados)
        {

            foreach (var item in ListaDiasFeriados)
            {

                if (this.view.btn1.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn1.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn1.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn2.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn2.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn2.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn3.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn3.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn3.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn4.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn4.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn4.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn5.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn5.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn5.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn6.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn6.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn6.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn7.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn7.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn7.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn8.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn8.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn8.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn9.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn9.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn9.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn10.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn10.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn10.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn11.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn11.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn11.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn12.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn12.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn12.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn13.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn13.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn13.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn14.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn14.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn14.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn15.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn15.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn15.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn16.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn16.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn16.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn17.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn17.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn17.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn18.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn18.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn18.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn19.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn19.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn19.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn20.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn20.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn20.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn21.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn21.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn21.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn22.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn22.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn22.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn23.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn23.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn23.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn24.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn24.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn24.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn25.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn25.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn25.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn26.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn26.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn26.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn27.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn27.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn27.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn28.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn28.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn28.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn29.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn29.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn29.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn30.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn30.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn30.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn31.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn31.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn31.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn32.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn32.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn32.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn33.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn33.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn33.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn34.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn34.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn34.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn35.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn35.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn35.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn36.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn36.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn36.ToolTip = item.DescripcionFeriado;
                    continue;
                }

                if (this.view.btn37.Content.ToString() == item.FechaFeriado.Day.ToString())
                {
                    this.view.btn37.Style = this.view.Resources["ButtonWeekend"] as Style;
                    this.view.btn37.ToolTip = item.DescripcionFeriado;
                    continue;
                }

            }





        }


        internal void CambiarEstiloDiaConActividades(TrackableCollection<PlanificacionDiariaProyectoDidactico> ListaActividadesDiarias)
        {


            var Dias = (from v in ListaActividadesDiarias                               
                               select v.Dia).ToList();



            foreach (var item in Dias)
            {

                if (this.view.btn1.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn1);
                    continue;
                }

                if (this.view.btn2.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn2);
                    continue;
                }

                if (this.view.btn3.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn3);
                    continue;
                }

                if (this.view.btn4.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn4);
                    continue;
                }

                if (this.view.btn5.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn5);
                    continue;
                }

                if (this.view.btn6.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn6);
                    continue;
                }

                if (this.view.btn7.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn7);
                    continue;
                }

                if (this.view.btn8.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn8);
                    continue;
                }

                if (this.view.btn9.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn9);
                    continue;
                }

                if (this.view.btn10.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn10);
                    continue;
                }

                if (this.view.btn11.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn11);
                    continue;
                }

                if (this.view.btn12.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn12);
                    continue;
                }

                if (this.view.btn13.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn13);
                    continue;
                }

                if (this.view.btn14.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn14);
                    continue;
                }

                if (this.view.btn15.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn15);
                    continue;
                }

                if (this.view.btn16.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn16);
                    continue;
                }

                if (this.view.btn17.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn17);
                    continue;
                }

                if (this.view.btn18.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn18);
                    continue;
                }

                if (this.view.btn19.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn19);
                    continue;
                }

                if (this.view.btn20.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn20);
                    continue;
                }

                if (this.view.btn21.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn21);
                    continue;
                }

                if (this.view.btn22.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn22);
                    continue;
                }

                if (this.view.btn23.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn23);
                    continue;
                }

                if (this.view.btn24.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn24);
                    continue;
                }

                if (this.view.btn25.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn25);
                    continue;
                }

                if (this.view.btn26.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn26);
                    continue;
                }

                if (this.view.btn27.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn27);
                    continue;
                }

                if (this.view.btn28.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn28);
                    continue;
                }

                if (this.view.btn29.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn29);
                    continue;
                }

                if (this.view.btn30.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn30);
                    continue;
                }

                if (this.view.btn31.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn31);
                    continue;
                }

                if (this.view.btn32.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn32);
                    continue;
                }

                if (this.view.btn33.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn33);
                    continue;
                }

                if (this.view.btn34.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn34);
                    continue;
                }

                if (this.view.btn35.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn35);
                    continue;
                }

                if (this.view.btn36.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn36);
                    continue;
                }

                if (this.view.btn37.Content.ToString() == item.ToString())
                {
                    this.ActualizarEstadoControl(this.view.btn37);
                    continue;
                }


















            }

        }






    }
}
